Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue with .c in folder name #126

Merged
merged 3 commits into from
May 11, 2023
Merged

Conversation

trollkarlen
Copy link
Contributor

put doom hack under doom define, to use run with -d doom

related to error #124 but not a total fix this just fixes so a wrapper can be created.
May break doom tests but not when the new define is set.

@trollkarlen
Copy link
Contributor Author

Should I change doom to a argument instead of a define, so it can be a runtime not a compile time patch ?
-doom

@trollkarlen
Copy link
Contributor Author

Maybe the same for trace_verbose ?
Will not change until i get your input.

@ArtemkaKun
Copy link
Contributor

I don't know if C2V should have different code for different projects

@trollkarlen
Copy link
Contributor Author

It has already :)

So make doom and trace_verbose arguments instead ?

@ArtemkaKun
Copy link
Contributor

I mean that doom specific hack should be removed and universal fix should be implemented

@trollkarlen
Copy link
Contributor Author

But thats a bigger task than fixing a issue in the code, and if we put that on every bug fix then there will be no bug fixes :/

@ArtemkaKun
Copy link
Contributor

ArtemkaKun commented May 9, 2023

In my opinion it's better to made a solid change one time, than made a few hacky quick fixes and introduce more complexity and potential bugs into the project.

In this case, what if tomorrow a new guy will come and said "my XYZ project requites specific changes to make it work", would we introduce new argument -XYZ that should be used for this specific project only? I don't think this is a good idea.

I appreciate your contribution, we just need to do it in another way.

Have you investigated why Doom requires that hack?

@trollkarlen
Copy link
Contributor Author

In my opinion it's better to made a solid change one time, than made a few hacky quick fixes and introduce more complexity and potential bugs into the project.

In this case, what if tomorrow a new guy will come and said "my XYZ project requites specific changes to make it work", would we introduce new argument -XYZ that should be used for this specific project only? I don't think this is a good idea.

This also just cancels that quick fix, so its not that its a new XYZ fix.

I appreciate your contribution, we just need to do it in another way.

Second it cant be made an argument easily because the some of the test relies on a bash script(https://github.com/vlang/doom/blob/master/build_whole_project.sh) thats not located in this git which is strange in it self.
So it need to be a compile time fix, for it to not get out of hand work wise.

Have you investigated why Doom requires that hack?

I guess this(c2v) and was written by someone that knows v and c very well from the beginning, and that person left it there for a reason. And that reason not being it is a easy fix or that maybe it require a change in doom.

@trollkarlen
Copy link
Contributor Author

trollkarlen commented May 9, 2023

So i think to move forward the best is to take changes incrementally and not force this fix to change all doom related issues.
But I can write a issue doom hacks in c2v so that can be tracked, separately.

@ArtemkaKun
Copy link
Contributor

Again, I don't think that C2V code should depends on project it translates, neither project, that works, should be changed to be able to be translated by C2V.

We can't introduce copile time things like

if DOOM {
   
} elseif X {

} elseif Y {

} else {

}

The original C2V code was created by @medvednikov , maybe he will help to understand why this Doom specific code is here and how it can be removed.

@trollkarlen
Copy link
Contributor Author

I changed the pull to not include the fix for doom src folder and let others fall on the same branch :/
So it should be clean now

@ArtemkaKun
Copy link
Contributor

Got it. I hope issue with Doom will be fixed somewhere in future.

Can you please explain to me how your fix works? I nit quite understand what your changes do

@trollkarlen
Copy link
Contributor Author

I tried to convert xml.c project to v and then i discovered that if you got .c in any folder name its also exchanged to .json so the change makes sure it only replace the last .c to . json and not all of them.

@ArtemkaKun
Copy link
Contributor

Do you think you could implement a test for this case?

@trollkarlen
Copy link
Contributor Author

trollkarlen commented May 9, 2023

Sure should be easy, except i need to avoid the doom hack 😁

Create anything in a ./src folder will make it change to that folder and fail because it cant find the file its trying to parse 😁

@ArtemkaKun
Copy link
Contributor

Not sure how this is connected to src/ folder but whatever. Seems we don't have an infrastructure for that kind of tests

@ArtemkaKun
Copy link
Contributor

I will try to review it asap and will merge if everything is ok

@trollkarlen
Copy link
Contributor Author

Test added, the same bug existed in the test runner :)

@trollkarlen
Copy link
Contributor Author

The hack added for doom that with chdir to 'src' is only seen if you dont have absolute paths. Just for reference.
I tried to create a failing testcase for this but the test runner runs with absolute paths on the conversion files.

@ArtemkaKun
Copy link
Contributor

So the hack with DOOM is needed only for CI checks?

@trollkarlen
Copy link
Contributor Author

So the hack with DOOM is needed only for CI checks?
No the opposite.

When it does the conversion if it finds '/src/' somewhere on the path it chdir to that location to i guess find a headerfile that in the wrong location. So if the path was relative from the start then the new relative path will be wrong.

Example:

v translate banana/src/test.c

it will fail because it will chdir to banana/src and then try to convert the file banana/src/test.c but that file does not exist.
But if you have the abs path it works even thou it chdir to banana/src because you started it with an absolute path.

Full test and example:

$ mkdir tests/src
$ cp -a tests/test.c tests/src/
$ v run . tests/src/test.c/1.hello.c
C to V translator 0.3.1
  translating tests/src/test.c/1.hello.c ... sh: line 1: tests/src/test.c/1.hello.json: No such file or directory

The file tests/src/test.c/1.hello.c could not be parsed as a C source file.
$ v run . $(pwd)/tests/src/test.c/1.hello.c
C to V translator 0.3.1
  translating $HOME/c2v/tests/src/test.c/1.hello.c ... Reformatted file: $HOME/c2v/tests/src/test.c/1.hello.v
 took    94 ms ; output .v file: test.c/1.hello.v
Translated   1 files in    94 ms.

@trollkarlen
Copy link
Contributor Author

trollkarlen commented May 10, 2023

Either way this should be ready for merge

$ git checkout 9a5bacb6bc6d5edf578b48890079245198c6af3a -b test-works   # this pull request                                                                                                                                      
Switched to a new branch 'test-works'                                                                                                                                                                    
$ cp -a tests/test.c .              # park the test from the new commit                                                                                                                                                                                
$ git checkout 811a8b7c320d1fda9a23d4a95ed5f84ccc1f2537 -b test-fail            # master and base of this pull                                                                                                                              
$ cp -a test.c/ tests/test.c      # get the test from the new commit                                                                   
$ v -g run tests/run_tests.vsh
building c2v...
done
Reformatted file: $HOME/dev/c2v/tests/1.hello.v
Already formatted file: $HOME/dev/c2v/tests/1.hello.v
$HOME/dev/c2v/tests/1.hello.c...  OK
Reformatted file: $HOME/dev/c2v/tests/11.enum_default.v
Already formatted file: $HOME/dev/c2v/tests/11.enum_default.v
$HOME/dev/c2v/tests/11.enum_default.c...  OK
Reformatted file: $HOME/dev/c2v/tests/12.if_stmt.v
Already formatted file: $HOME/dev/c2v/tests/12.if_stmt.v
$HOME/dev/c2v/tests/12.if_stmt.c...  OK
Reformatted file: $HOME/dev/c2v/tests/13.switch.v
Already formatted file: $HOME/dev/c2v/tests/13.switch.v
$HOME/dev/c2v/tests/13.switch.c...  OK
Reformatted file: $HOME/dev/c2v/tests/14.default.v
Already formatted file: $HOME/dev/c2v/tests/14.default.v
$HOME/dev/c2v/tests/14.default.c...  OK
Reformatted file: $HOME/dev/c2v/tests/15.multi_var_decl.v
Already formatted file: $HOME/dev/c2v/tests/15.multi_var_decl.v
$HOME/dev/c2v/tests/15.multi_var_decl.c...  OK
Reformatted file: $HOME/dev/c2v/tests/2.if.v
Already formatted file: $HOME/dev/c2v/tests/2.if.v
$HOME/dev/c2v/tests/2.if.c...  OK
Reformatted file: $HOME/dev/c2v/tests/3.if_switch_enum.v
Already formatted file: $HOME/dev/c2v/tests/3.if_switch_enum.v
$HOME/dev/c2v/tests/3.if_switch_enum.c...  OK
Reformatted file: $HOME/dev/c2v/tests/4.for.v
Already formatted file: $HOME/dev/c2v/tests/4.for.v
$HOME/dev/c2v/tests/4.for.c...  OK
Reformatted file: $HOME/dev/c2v/tests/5.struct.v
Already formatted file: $HOME/dev/c2v/tests/5.struct.v
$HOME/dev/c2v/tests/5.struct.c...  OK
Reformatted file: $HOME/dev/c2v/tests/6.types.v                                                                                                                                                  
Already formatted file: $HOME/dev/c2v/tests/6.types.v                                                                                                                                            
$HOME/dev/c2v/tests/6.types.c...  OK                                                                                                                                                             
sh: line 1: $HOME/dev/c2v/tests/src/test.json/1.hello.json: No such file or directory                                                                                                            
                                                                                                                                                                                                         
The file $HOME/dev/c2v/tests/src/test.c/1.hello.c could not be parsed as a C source file.                                                                                                        
$HOME/dev/c2v/tests/src/test.c/1.hello.c...  FAIL                                                                                                                                                
$ rm -fr tests/test.c   # remove to not get conflict                                                                                                                                                                                  
$ git checkout test-works                                                                                                                                                                                
Switched to branch 'test-works'                                                                                                                                                                          
$ v -g run tests/run_tests.vsh                                                                                                                                                                           
building c2v...                                                                                                                                                                                          
done
Reformatted file: $HOME/dev/c2v/tests/1.hello.v
Already formatted file: $HOME/dev/c2v/tests/1.hello.v
$HOME/dev/c2v/tests/1.hello.c...  OK
Reformatted file: $HOME/dev/c2v/tests/11.enum_default.v
Already formatted file: $HOME/dev/c2v/tests/11.enum_default.v
$HOME/dev/c2v/tests/11.enum_default.c...  OK
Reformatted file: $HOME/dev/c2v/tests/12.if_stmt.v
Already formatted file: $HOME/dev/c2v/tests/12.if_stmt.v
$HOME/dev/c2v/tests/12.if_stmt.c...  OK
Reformatted file: $HOME/dev/c2v/tests/13.switch.v
Already formatted file: $HOME/dev/c2v/tests/13.switch.v
$HOME/dev/c2v/tests/13.switch.c...  OK
Reformatted file: $HOME/dev/c2v/tests/14.default.v
Already formatted file: $HOME/dev/c2v/tests/14.default.v
$HOME/dev/c2v/tests/14.default.c...  OK
Reformatted file: $HOME/dev/c2v/tests/15.multi_var_decl.v
Already formatted file: $HOME/dev/c2v/tests/15.multi_var_decl.v
$HOME/dev/c2v/tests/15.multi_var_decl.c...  OK
Reformatted file: $HOME/dev/c2v/tests/2.if.v
Already formatted file: $HOME/dev/c2v/tests/2.if.v
$HOME/dev/c2v/tests/2.if.c...  OK
Reformatted file: $HOME/dev/c2v/tests/3.if_switch_enum.v
Already formatted file: $HOME/dev/c2v/tests/3.if_switch_enum.v
$HOME/dev/c2v/tests/3.if_switch_enum.c...  OK
Reformatted file: $HOME/dev/c2v/tests/4.for.v
Already formatted file: $HOME/dev/c2v/tests/4.for.v
$HOME/dev/c2v/tests/4.for.c...  OK
Reformatted file: $HOME/dev/c2v/tests/5.struct.v
Already formatted file: $HOME/dev/c2v/tests/5.struct.v
$HOME/dev/c2v/tests/5.struct.c...  OK
Reformatted file: $HOME/dev/c2v/tests/6.types.v
Already formatted file: $HOME/dev/c2v/tests/6.types.v
$HOME/dev/c2v/tests/6.types.c...  OK
Reformatted file: $HOME/dev/c2v/tests/src/test.c/1.hello.v
Already formatted file: $HOME/dev/c2v/tests/src/test.c/1.hello.v
$HOME/dev/c2v/tests/src/test.c/1.hello.c...  OK
Reformatted file: $HOME/dev/c2v/tests/test.c/1.hello.v
Already formatted file: $HOME/dev/c2v/tests/test.c/1.hello.v
$HOME/dev/c2v/tests/test.c/1.hello.c...  OK
Reformatted file: $HOME/dev/c2v/tests/10.jni.v
$HOME/dev/c2v/tests/10.jni.h...  OK
Reformatted file: $HOME/dev/c2v/tests/7.api_types.v
$HOME/dev/c2v/tests/7.api_types.h...  OK
Reformatted file: $HOME/dev/c2v/tests/8.simple_func_header.v
$HOME/dev/c2v/tests/8.simple_func_header.h...  OK
Reformatted file: $HOME/dev/c2v/tests/9.func_declaration.v
$HOME/dev/c2v/tests/9.func_declaration.h...  OK

@ArtemkaKun
Copy link
Contributor

So maybe we can make sure that path, provided in the parameters for c2v command, is always absolute? For example, we can use os.is_abs_path and os.abs_path for that

@trollkarlen
Copy link
Contributor Author

So maybe we can make sure that path, provided in the parameters for c2v command, is always absolute? For example, we can use os.is_abs_path and os.abs_path for that

Yes, thats a possible workaround but not for this pull request but for #127.
But it can generate other issues due to the chdir other header files can maybe not be found in other projects.

@ArtemkaKun
Copy link
Contributor

Ok, got it. So I will merge that PR after a codereview

tests/run_tests.vsh Outdated Show resolved Hide resolved
src/c2v.v Outdated Show resolved Hide resolved
src/c2v.v Show resolved Hide resolved
Signed-off-by: Robert Marklund <[email protected]>
@trollkarlen
Copy link
Contributor Author

It wasn't so easy to create a utils file and have that imported in the test runner so it became like this instead.
There was also a copy paste bug(or waste) in the test file that got found and resolved this way.

@ArtemkaKun ArtemkaKun merged commit d84d969 into vlang:master May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants